# 定义：被定义在一对[元素, 元素, 元素]的数据， 称为列表list
# 可变

# 列表解析， 快速生成列表， 测试数据
data_01 = [ i for i in range(1,6)]
print(data_01)

data_02 = ["192.168.1.%s" % i for i in range(5)]
print(data_02)

data_03 = [ "linux" , "mysql" , "python"]
print("linux" in data_03)
print(data_03[0] in data_03)

data_04 = [["mysql , 5.7"] , ["linux , 7"] , ["python , 11"]]
print(len(data_04))
print("mysql" in data_04[0])
print("mysql" in data_04[0][0])

print("--------" * 7)

# 索引 左：0  右：-1   是可变的！！！！！！！！
data_05 = ["nginx", "python", "tomcat", "mysql"]
data_06 = [["docker", "1.26"], ["mysql", "5.7"]]
print(data_05[0])
print(data_06[1][1])

# 修改
data_05[0] = "linux"
print(data_05)
data_06[1][1] = "8.0"
print(data_06)

print("--------" * 7)

# 列表对象操作方法
# 追加
data_07 = ["vim"]
data_07.append("ssh")
print(data_07)
data_07.append("http")
print(data_07)

# 插入
data_08 = ["nginx", "mysql", "tomcat"]
data_08.insert(1,"docker")
print(data_08)
data_08.insert( -1,"k8s")
print(data_08)

#删除 pop()
#删除最后一个数据，并返回删除的数据
data_09 = [ "nginx", "tomcat", "IIS", "httpd" ]
dele = data_09.pop()
print(data_09)
print("删除的数据为:%s" % dele)
shanchu = data_09.pop()
print(data_09)
print("删除的数据为:%s" % shanchu)

#删除  remove()
data_10 = [ "nginx", "tomcat", "IIS", "httpd" ]
data_10.remove("tomcat")
print(data_10)

print("------------" * 7)
#遍历列表
data_11 = ["192.168.1.%s" % i for i in range(1,6)]
print(data_11)
for i in data_11:
    print("scp /etc/hosts root@%s:/etc/hosts" % i)
data_12 = [["docker", "1.29"], ["centos", "7"], ["mysql", "5.7"]]
for i ,j in data_12:
    print("软件名称为:%s  版本名称为:%s" % (i,j))

